using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using SFS.SampleApp.Web.Mvc.Resources;
using System.Runtime.Serialization;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Extensions;
using BO = SFS.SampleApp.BusinessObjects;
using System.Web.Mvc;
using SFSdotNet.Framework.Web.Mvc.Validation;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Resources;
using SFSdotNet.Framework.Entities.Metadata;


namespace SFS.SampleApp.Web.Mvc.Models.SalesOrderDetails 
{
	public partial class SalesOrderDetailModel: ModelBase{
		public SalesOrderDetailModel()
        {
		}
		public override string Id
        {
            get
            {
                return this.SalesOrderID.ToString();
            }
        }
			
			
        public override string ToString()
        {
		
            return this.SalesOrderID.ToString();
		
        }    
			
	
		[SystemProperty()]		
		public Int32? SalesOrderID{ get; set; }
		
	
		[SystemProperty()]		
		public Int32? SalesOrderDetailID{ get; set; }
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_ORDERQTY_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderDetailResources))]
		
	[RelationFilterable()]
	[DataType("Integer")]
	[LocalizedDisplayName("ORDERQTY", NameResourceType=typeof(SalesOrderDetailResources))]
	public Int16   OrderQty { get; set; }
    public string OrderQtyText {
        get {
				return OrderQty.ToString();
				
        }
        
    }

		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_UNITPRICE_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderDetailResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("UNITPRICE", NameResourceType=typeof(SalesOrderDetailResources))]
	public Decimal   UnitPrice { get; set; }
    public string UnitPriceText {
        get {
				return UnitPrice.ToString();
				
        }
        
    }

		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_UNITPRICEDISCOUNT_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderDetailResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("UNITPRICEDISCOUNT", NameResourceType=typeof(SalesOrderDetailResources))]
	public Decimal   UnitPriceDiscount { get; set; }
    public string UnitPriceDiscountText {
        get {
				return UnitPriceDiscount.ToString();
				
        }
        
    }

		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_LINETOTAL_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderDetailResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("LINETOTAL", NameResourceType=typeof(SalesOrderDetailResources))]
	public Decimal   LineTotal { get; set; }
    public string LineTotalText {
        get {
				return LineTotal.ToString();
				
        }
        
    }

		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[SystemProperty()]
	[LocalizedDisplayName("ROWGUID", NameResourceType=typeof(SalesOrderDetailResources))]
	public Guid   rowguid { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_MODIFIEDDATE_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderDetailResources))]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("MODIFIEDDATE", NameResourceType=typeof(SalesOrderDetailResources))]
	public DateTime   ModifiedDate { get; set; }
	public string ModifiedDateText {
        get {
            if (ModifiedDate != null)
			
                return ((DateTime)ModifiedDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.ModifiedDate = Convert.ToDateTime(value);
    }
		}
		
		
	
[Exportable()]
		
	[RelationFilterable(DataClassProvider = typeof(Controllers.ProductsController), GetByKeyMethod="GetByKey", GetAllMethod = "GetAll", DataPropertyText = "Name", DataPropertyValue = "ProductID", FiltrablePropertyPathName="Product.ProductID")]	

	[LocalizedDisplayName("PRODUCT", NameResourceType=typeof(SalesOrderDetailResources))]
	public Int32  ? FkProduct { get; set; }
		[LocalizedDisplayName("PRODUCT", NameResourceType=typeof(SalesOrderDetailResources))]
	[Exportable()]
	public string  FkProductText { get; set; }
    public string FKProductSafeKey { get; set; }

	
		
	
[Exportable()]
		
	[RelationFilterable(DataClassProvider = typeof(Controllers.SalesOrderHeadersController), GetByKeyMethod="GetByKey", GetAllMethod = "GetAll", DataPropertyText = "SalesOrderNumber", DataPropertyValue = "SalesOrderID", FiltrablePropertyPathName="SalesOrderHeader.SalesOrderID")]	

	[LocalizedDisplayName("SALESORDERHEADER", NameResourceType=typeof(SalesOrderDetailResources))]
	public Int32  ? FkSalesOrderHeader { get; set; }
		[LocalizedDisplayName("SALESORDERHEADER", NameResourceType=typeof(SalesOrderDetailResources))]
	[Exportable()]
	public string  FkSalesOrderHeaderText { get; set; }
    public string FKSalesOrderHeaderSafeKey { get; set; }

	
		
		
	public override string SafeKey
   	{
		get
        {
			if(this.SalesOrderID != null && this.SalesOrderDetailID != null)
				return SFSdotNet.Framework.Entities.Utils.GetKey(this ,"SalesOrderID", "SalesOrderDetailID").Replace("/","-");
			else
				return String.Empty;
		}
    }		
		public void Bind(SalesOrderDetailModel model){
            
		this.SalesOrderID = model.SalesOrderID;
		this.SalesOrderDetailID = model.SalesOrderDetailID;
		this.OrderQty = model.OrderQty;
		this.UnitPrice = model.UnitPrice;
		this.UnitPriceDiscount = model.UnitPriceDiscount;
		this.LineTotal = model.LineTotal;
		this.rowguid = model.rowguid;
		this.ModifiedDate = model.ModifiedDate;
        }

        public BusinessObjects.SalesOrderDetail GetBusinessObject()
        {
            BusinessObjects.SalesOrderDetail result = new BusinessObjects.SalesOrderDetail();
	if (this.SalesOrderID != null )
				result.SalesOrderID = (Int32)this.SalesOrderID;
				
	if (this.SalesOrderDetailID != null )
				result.SalesOrderDetailID = (Int32)this.SalesOrderDetailID;
				
	if (this.OrderQty != null )
				result.OrderQty = (Int16)this.OrderQty;
				
	if (this.UnitPrice != null )
				result.UnitPrice = (Decimal)this.UnitPrice;
				
	if (this.UnitPriceDiscount != null )
				result.UnitPriceDiscount = (Decimal)this.UnitPriceDiscount;
				
	if (this.LineTotal != null )
				result.LineTotal = (Decimal)this.LineTotal;
				
	if (this.rowguid != null )
				result.rowguid = (Guid)this.rowguid;
				
				result.ModifiedDate = (DateTime)this.ModifiedDate;		
				
	result.Product = new BusinessObjects.Product() { ProductID= (Int32)this.FkProduct };
				
	result.SalesOrderHeader = new BusinessObjects.SalesOrderHeader() { SalesOrderID= (Int32)this.FkSalesOrderHeader };
				



            return result;
        }
        public void Bind(BusinessObjects.SalesOrderDetail businessObject)
        {
            
			this.SalesOrderID = businessObject.SalesOrderID;
				
			this.SalesOrderDetailID = businessObject.SalesOrderDetailID;
				
			this.OrderQty = businessObject.OrderQty;
				
			this.UnitPrice = businessObject.UnitPrice;
				
			this.UnitPriceDiscount = businessObject.UnitPriceDiscount;
				
			this.LineTotal = businessObject.LineTotal;
				
			this.rowguid = businessObject.rowguid;
				
				this.ModifiedDate = (DateTime)businessObject.ModifiedDate;
	        if (businessObject.Product != null){
	                	this.FkProductText = businessObject.Product.Name.Trim().Replace("\t", String.Empty); 
										
										
				this.FkProduct = businessObject.Product.ProductID;
                this.FKProductSafeKey  = SFSdotNet.Framework.Entities.Utils.GetKey(businessObject.Product,"ProductID").Replace("/","-");

			}
	        if (businessObject.SalesOrderHeader != null){
	                	this.FkSalesOrderHeaderText = businessObject.SalesOrderHeader.SalesOrderNumber.Trim().Replace("\t", String.Empty); 
										
										
				this.FkSalesOrderHeader = businessObject.SalesOrderHeader.SalesOrderID;
                this.FKSalesOrderHeaderSafeKey  = SFSdotNet.Framework.Entities.Utils.GetKey(businessObject.SalesOrderHeader,"SalesOrderID").Replace("/","-");

			}
           
        }
	}
}
